package com.banshuibao.bsb_android.fragment;


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.adapter.CounselorUserHomeAdapter;
import com.banshuibao.bsb_android.adapter.HomeBaseAdapter;
import com.banshuibao.bsb_android.model.CoachModel;
import com.banshuibao.bsb_android.model.ExpertResultModel;
import com.banshuibao.bsb_android.model.MediaModel;
import com.banshuibao.bsb_android.model.UserMessageModel;
import com.banshuibao.bsb_android.pulltolistview.PullToRefreshBase;
import com.banshuibao.bsb_android.pulltolistview.PullToRefreshListView;
import com.banshuibao.bsb_android.util.IntentManager;
import com.banshuibao.bsb_android.view.RedImageView;

/**
 * A simple {@link Fragment} subclass.
 */
public class CounselorUserHomeFragment extends BaseHomeFragment implements PullToRefreshListView.OnRefreshListener2<ListView>, HomeBaseAdapter.HomeOnItemClickListener {

    private PullToRefreshListView ptrlv;
    private CounselorUserHomeAdapter commonUserHomeAdapter;
    private ImageView search, fast_question;
    private RedImageView msg;

    public CounselorUserHomeFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_home_counselor, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        commonUserHomeAdapter = new CounselorUserHomeAdapter(getActivity());
        commonUserHomeAdapter.setHomeOnItemClickListener(this);
        ptrlv = view.findViewById(R.id.pull);
        ptrlv.setOnRefreshListener(this);
        search = view.findViewById(R.id.search);
        msg = view.findViewById(R.id.msg);
        msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentManager.goSystemInformationActivity(getActivity());
            }
        });
//        fast_question = view.findViewById(R.id.fast_question);
//        fast_question.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                IntentManager.goIfAnswerActivity(getActivity());
//            }
//        });
        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                IntentManager.goSearchActivity(getActivity());
            }
        });
        setPullToRefreshListView(ptrlv, commonUserHomeAdapter);
        loadData();
    }

    private void loadData() {
        loadAdImage("0");
        loadAdImage("1");
        loadCoachData();
        loadAnswer();
        //loadLive();
        loadInterview();
        loadMedia("1");
        //loadMedia("2");
        loadOfficeData();
        loadOfficeGoodsData();
        loadUserMessage();
        loadEventData();
    }

    @Override
    void updateUserMessage(UserMessageModel.Data user) {
        super.updateUserMessage(user);
        if (getView() != null) {
            ((TextView) getView().findViewById(R.id.title_text)).setText(user.getFirmName() + "欢迎您！");
            getView().findViewById(R.id.title_text).setSelected(true);
        }
    }

    @Override
    public void goFastQuestion() {
        IntentManager.goIfAnswerActivity(getActivity());
    }

    @Override
    public void goCoach(CoachModel.Data item) {
        IntentManager.goCoachPolicyDetailActivity(getActivity(), item.getUuid(), item.getTitle(), item.getCreateDate());
    }

    @Override
    public void goAnswer(ExpertResultModel.DataBean dataBean) {
        IntentManager.goExpertDetailActivity(getActivity(), dataBean.getUuid());
    }

    @Override
    public void goLive(String title, String roomId) {

    }

    @Override
    public void goMedia(MediaModel.Data data) {
        buyMedia(data);
    }

    @Override
    public void goOffice(String uuid) {
        IntentManager.goOfficeDetailActivity(getActivity(), uuid);
    }

    @Override
    public void goGoods(String uuid) {
        IntentManager.goGoodsDetailActivity(getActivity(), uuid);
    }

    @Override
    public void goTag() {

    }

    @Override
    public void goInterview(MediaModel.Data interviewData) {
        buyMedia(interviewData);
    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase refreshView) {
        loadData();
    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase refreshView) {

    }

    @Override
    public void onSaveInstanceState(@NonNull Bundle outState) {
        // super.onSaveInstanceState(outState);
    }
}
